<?php

namespace App\Http\Model;


class Activity extends Base
{
    protected $hidden = [
        'remaining_number', 'is_active', 'sort_order', 'updated_at', 'created_at'
    ];

    protected $fillable = ['number'];

    public function goods()
    {
        return $this->belongsTo('App\Http\Model\Goods');
    }

    public function log()
    {
        return $this->HasOne('App\Http\Model\ActivityLog');
    }

    public function share_log()
    {
        return $this->HasOne('App\Http\Model\ActivityShareLog');
    }

    public function getImgUrlAttribute($value)
    {
        if (empty($value)) return $value;

        return env('CDN_DOMAIN') . $value;
    }

    public function getStartAtAttribute($date)
    {
        return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->timestamp;
    }

    public function getEndAtAttribute($date)
    {
        return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->timestamp;
    }

}
